﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ChucNang_Admin_Admin_XemDanhSachDoiTac : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        btnXoa.Attributes["onclick"] = "return confirm('Chắc chắn xóa?')";
            DataDSTableAdapters.DOITACTableAdapter dtadapter = new DataDSTableAdapters.DOITACTableAdapter();

            int tongdong = int.Parse(dtadapter.DOITAC_TongSoDong().ToString());
            int currentPage = 0;
            if (Request["page"] != null)
                currentPage = int.Parse(Request["page"]);
            int rowPerPage = int.Parse(ConfigurationSettings.AppSettings["RowPerPage"]);
            int numOfPage = tongdong / rowPerPage;
            if (tongdong % rowPerPage != 0)
                numOfPage++;
            PageInterface1.currentPageName = GlobalFunctions.GetCurrentPageName();
            PageInterface1.currentPageNumber = currentPage;
            PageInterface1.totalNumberOfPage = numOfPage;

            int startIndex = (rowPerPage * currentPage);
            if (!IsPostBack)
            {
                DataList_DSDT.DataSource = dtadapter.DOITAC_LayTatCa_Page(startIndex, rowPerPage);
                DataList_DSDT.DataBind();
            }
            


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_ThemDoiTac.aspx");
    }
    protected void btnXoa_Click(object sender, EventArgs e)
    {
        DataDSTableAdapters.DOITACTableAdapter dtadapter = new DataDSTableAdapters.DOITACTableAdapter();
        int? kq = 0;
        int count = 0;

        //Message box here
        for (int i = 0; i < DataList_DSDT.Items.Count; i++)
        {
            Label lb = (Label)DataList_DSDT.Items[i].FindControl("lbMaDoiTac");
            CheckBox ck = (CheckBox)DataList_DSDT.Items[i].FindControl("ckXoa");
            if (ck.Checked == true)
            {
                //do delete seleted items
                int maDT = int.Parse(lb.Text);
                dtadapter.DOITAC_XoaTheoId(maDT, ref kq);
                count++;
                if (kq != 0)
                    Response.Write("<script>alert('Lỗi xóa dữ liệu!')</script>");

            }
        }
        if (count == 0)
        {
            Response.Write("<script>alert('Không có dòng nào được chọn!')</script>");
            return;
        }
        Response.Write("<script>alert('Xóa thành công!'); window.location.href='/SMO/ChucNang/Admin/Admin_XemDanhSachDoiTac.aspx'</script>");
    }
}
